package com.kehon.sevletdemo;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author zhang peng yang ming
 * @CopyRight (C) http://www.csdn.com
 * @brief
 * @email 122162005@qq.com
 * @date 2018-07-16
 */
public class LoginServlet implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        servletResponse.setContentType("text/html;charset=UTF-8");
        String username = servletRequest.getParameter("username");  // 获取用户名
        String password = servletRequest.getParameter("password");  // 获取密码

        if ("admin".equals(username) && "12345".equals(password)) {
            servletResponse.getWriter().write("<h1>" + username + ": 登录成功</h1>");
            servletResponse.getWriter().write("<a href='/add.do'>添加员工</a> ");
        }
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
